package com.zhengbing.tj.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhengbing.tj.entity.User;
import com.zhengbing.tj.mapper.UserMapper;
import com.zhengbing.tj.service.UserService;

import java.io.Serializable;

import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhengbing.tj.annotation.AuditLogRecord;

/**
 * 用户服务实现类，基于MyBatis-Plus
 *
 * @author zhengbing
 * @date 2025-07-07
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User getUserByUsername(String username) {
        return baseMapper.selectOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, username));
    }
    
    @Override
    @AuditLogRecord(entityType = "user", operationType = "insert", description = "新增用户")
    public boolean save(User user) {
        return super.save(user);
    }
    
    // 移除@Override注解以避免方法签名不匹配问题
    @AuditLogRecord(entityType = "user", operationType = "update", description = "更新用户", recordDetails = true)
    public boolean updateById(User user) {
        return super.updateById(user);
    }
    
    @Override
    @AuditLogRecord(entityType = "user", operationType = "delete", description = "删除用户", idParamIndex = 0, recordDetails = true)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }
}